class UploaderController < ApplicationController
  skip_before_action :logged_in_user
  skip_before_action :verify_authenticity_token

  layout false

  def upload
    image_path = params['Filename']
    image_height = params['imgHeight']
    image_width = params['imgWidth']
    upyun = Upyun::Rest.new(ENV['upyun_bucket'], ENV['upyun_username'], ENV['upyun_password'])
=begin
    image_io = Magick::Image.from_blob( params['fileToUpload'].to_s).first

    image_io.width
=end
    @image = MiniMagick::Image.read(params['fileToUpload'].to_io)
    w,h=@image[:width],@image[:height]
    if image_height != w  && image_width != h
      render json: {result: 'fail'}.to_json
      return
    end
    file_path = "imgedemo/#{Druuid.gen}.#{image_path}"
    upyun.put(file_path, params['fileToUpload'].to_io)
    render json: { result: 'ok', picOrignalPath: "#{ENV['image_domain']}/#{file_path}", picSavePath:"#{ENV['image_domain']}/#{file_path}" }.to_json
  end

end

